<template>
  <div :style="{ backgroundColor: 'var(--color-f5)' }">
    <div class="container-xl bg-white m-mt-6">
      <div class="row"
        :style="{ fontWeight: 700, fontSize: '32px', color: '#434343', paddingTop: '48px', paddingBottom: '48px' }">
        <div class="col" :style="{ paddingLeft: '48px' }">比赛列表</div>
      </div>
      <div class="row"
        :style="{ color: 'var(--color-43)', fontWeight: 700, lineHeight: '48px', height: '48px', borderBottom: '1px solid #C4C4C4' }">
        <div class="col" :style="{ paddingLeft: '48px' }">比赛名</div>
        <div :style="{ width: '120px' }">类型</div>
        <div :style="{ width: '238px' }">比赛时间</div>
        <div :style="{ width: '120px', }">计时方式</div>
        <div :style="{ width: '176px', paddingRight: '48px' }">比赛时长</div>
      </div>
      <activityitem v-for="(v, key) in getactivity" :key="key" :activity="v"></activityitem>
      <div class="row" :style="{ paddingTop: '48px', paddingBottom: '48px' }">
        <div class="col text-right">
          <el-pagination :page-size="limit" :total="getactivitycount" @current-change="change"
            layout="prev, pager, next" :current-page="Math.floor(offset / limit) + 1"></el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { debounce } from "underscore";
import { useStore } from "vuex";

import { computed, inject, onMounted, ref, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import activityitem from '../../../components/activity/listmenu.vue';
import { Storekey } from "../../../interface";

// 码客行
const tenant_id = inject<string | undefined>('tenant_id', undefined)

const store = useStore(Storekey)
const route = useRoute()
const order = computed(() => {
  return route.query.order as string
})



const offset = computed(() => {
  return Number(route.query.offset) || 0
})

const limit = computed(() => {
  return Number(route.query.limit) || 20
})

const getactivity = computed(() => {
  return store.state.activity?.rows
})

const getactivitycount = computed(() => {
  return store.state.activity?.count
})

watch(() => [limit.value, offset.value, order.value], () => {
  if (route.name === '竞赛') {
    start()
  }
})

const debouncet1 = ref(debouncet())

function start() {
  debouncet1.value()
}

onMounted(() => {
  start()
})

const router = useRouter()

function change(r: number) {
  router.push({
    name: "竞赛",
    query: {
      limit: limit.value,
      order: order.value,
      offset: (r - 1) * limit.value,
    },
  });
}

function debouncet() {
  return debounce(() => {
    store.dispatch("actionactivity", {
      tenant_id, // 码客行
      _order: order.value,
      _offset: offset.value,
      _limit: limit.value,
    });
  }, 300);
}



</script>

<style scoped>
.lin {
  line-height: 130px;
  margin-left: 70px;
  margin-right: 80px;
  width: 160px;
}

.lin .el-image__inner {
  vertical-align: middle;
}

.d-inline-block {
  height: 130px;
}

h4 a {
  font-size: 18px;
  font-family: Microsoft YaHei;
  font-weight: bold;
  color: #333;
  text-decoration: none;
  line-height: 28px;
  display: inline-block;
}

.but-ac {
  width: 140px;
  height: 40px;
  border-radius: 20px;
  font-size: 20px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #ffffff;
  line-height: 40px;
  cursor: pointer;
  display: inline-block;
  text-align: center;
  text-decoration: none;
}

.div-bor-1 {
  border-color: var(--color-cheng);
}

.div-bor-4 {
  border-color: #c4c6d2;
}

.but-1 {
  background: var(--color-cheng);
}

.but-4 {
  background: #c4c6d2;
}

.el-tag {
  line-height: 28px;
  font-size: 14px;
}
</style>
